home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Jotto code ƒ / jotto main window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  6.0 KB  |  282 lines  |  [TEXT/MMCC]

  1. #include "jotto main window.h"
  2. #include "jotto meat.h"
  3. #include "jotto endgame.h"
  4. #include "jotto graphics.h"
  5. #include "jotto keys.h"
  6. #include "jotto environment.h"
  7. #include "jotto load-save.h"
  8. #include "environment.h"
  9. #include "util.h"
  10. #include "dialogs.h"
  11. #include "program globals.h"
  12. #include "pict utilities.h"
  13. #include "wipe dispatch.h"
  14. #include "graphics.h"
  15. #include "window layer.h"
  16.  
  17. static    short            gOldForegroundTime;        /* stored foreground wait time */
  18. static    Boolean            gSetupDone=FALSE;
  19.  
  20. CIconHandle        gColorIcons[3];
  21. Handle            gBWIcons[3];
  22. PicHandle        gBackgroundPict=0L;
  23.  
  24. void SetupTheMainWindow(WindowPtr theWindow)
  25. {
  26.     unsigned char    *titleStr="\pJotto ][";
  27.     short            i;
  28.     FSSpec            theFS;
  29.     
  30.     SetWindowMaxDepth(theWindow, 8);
  31.     SetWindowDepth(theWindow, 8);
  32.     SetWindowType(theWindow, noGrowDocProc);
  33.     SetWindowHasCloseBox(theWindow, TRUE);
  34.     SetWindowTitle(theWindow, titleStr);
  35.     SetWindowIsFloat(theWindow, FALSE);
  36.     SetWindowAutoCenter(theWindow, TRUE);
  37.     SetWindowWidth(theWindow, 300);
  38.     SetWindowHeight(theWindow, 300);
  39.     theFS.name[0]=0x00;
  40.     SetWindowFS(theWindow, theFS);
  41.     SetWindowIsModified(theWindow, FALSE);
  42.     
  43.     if (gSetupDone)
  44.         return;
  45.     
  46.     for (i=0; i<3; i++)
  47.     {
  48.         if (gHasColorQD)
  49.             gColorIcons[i]=GetCIcon(128+i);
  50.         gBWIcons[i]=GetIcon(128+i);
  51.     }
  52.     
  53.     gSetupDone=TRUE;
  54. }
  55.  
  56. void ShutDownTheMainWindow(void)
  57. {
  58.     short            i;
  59.     
  60.     for (i=0; i<3; i++)
  61.     {
  62.         if (gHasColorQD)
  63.             DisposeCIcon(gColorIcons[i]);
  64.         ReleaseResource(gBWIcons[i]);
  65.     }
  66.  
  67.     gBackgroundPict=ReleaseThePict(gBackgroundPict);
  68. }
  69.  
  70. Boolean CloseTheMainWindow(WindowPtr theWindow)
  71. {
  72.     ModalFilterUPP    procFilter = NewModalFilterProc(ThreeButtonFilter);
  73.     short            result;
  74.     
  75.     if (WindowIsModifiedQQ(theWindow))
  76.     {
  77.         SetCursor(&qd.arrow);
  78.         PositionDialog('ALRT', saveAlert);
  79.         ParamText(GetWindowTitle(theWindow), "\p", "\p", "\p");
  80.         result=Alert(saveAlert, procFilter);
  81.         DisposeRoutineDescriptor(procFilter);
  82.         switch (result)
  83.         {
  84.             case 1:    /* save */
  85.                 LoadSaveDispatch(FALSE, TRUE, 0L);
  86.                 if (WindowIsModifiedQQ(theWindow))    /* save didn't work for some reason */
  87.                     return FALSE;
  88.                 break;
  89.             case 2:     /* cancel */
  90.                 return FALSE;
  91.                 break;
  92.             case 3:    /* don't save */
  93.                 break;
  94.         }
  95.     }
  96.     
  97.     gCustomCursor=FALSE;
  98.     
  99.     return TRUE;
  100. }
  101.  
  102. void KeyPressedInMainWindow(WindowPtr theWindow, unsigned char theChar)
  103. {
  104.     ObscureCursor();
  105.     
  106.     if (GameInProgressQQ())
  107.     {
  108.         if ((theChar==0x0d) || (theChar==0x03))
  109.             UserHitReturn(theWindow);
  110.         else if ((theChar==0x1c) || (theChar==0x08))
  111.             UserHitLeftArrow(theWindow, theChar);
  112.         else if (theChar==0x1d)
  113.             UserHitRightArrow(theWindow);
  114.         else if ((((theChar&0xdf)>='A') && ((theChar&0xdf)<='Z')) || (theChar==' '))
  115.             UserHitLetter(theWindow, theChar);
  116.     }
  117.     else if (EndGameShowingQQ())
  118.     {
  119.         SetEndGame(FALSE);
  120.         UpdateTheWindow(theWindow);
  121.     }
  122.     
  123.     SetWindowIsModified(theWindow, TRUE);
  124. }
  125.  
  126. void MouseClickedInMainWindow(WindowPtr theWindow, Point thePoint)
  127. {
  128.     Rect        theRect;
  129.     short        i,target;
  130.     
  131.     if (GameInProgressQQ())
  132.     {
  133.         theRect.top=31;
  134.         theRect.bottom=theRect.top+38;
  135.         theRect.left=(GetWindowWidth(theWindow))/2-99-((gNumLetters==6) ? 20 : 0);
  136.         theRect.right=theRect.left+38;
  137.         target=-1;
  138.         for (i=0; i<gNumLetters; i++)
  139.         {
  140.             if (PtInRect(thePoint, &theRect))
  141.             {
  142.                 target=i;
  143.                 i=gNumLetters;
  144.             }
  145.             theRect.left+=40;
  146.             theRect.right+=40;
  147.         }
  148.         
  149.         if (target!=-1)
  150.         {
  151.             DrawOneChar(theWindow);
  152.             gWhichChar=target;
  153.             HighlightChar(theWindow);
  154.         }
  155.     }
  156.     else if (EndGameShowingQQ())
  157.     {
  158.         SetEndGame(FALSE);
  159.         UpdateTheWindow(theWindow);
  160.     }
  161. }
  162.  
  163. void ActivateTheMainWindow(WindowPtr theWindow)
  164. {
  165.     gOldForegroundTime=gForegroundWaitTime;
  166.     gForegroundWaitTime=0;
  167. }
  168.  
  169. void DeactivateTheMainWindow(WindowPtr theWindow)
  170. {
  171.     gForegroundWaitTime=gOldForegroundTime;
  172. }
  173.  
  174. void DrawTheMainWindow(WindowPtr theWindow, short theDepth)
  175. {
  176.     RGBColor        oldForeColor, oldBackColor;
  177.     GrafPtr            curPort;
  178.     Rect            theRect;
  179.     short            i;
  180.     Str255            tempStr;
  181.     char            oldChar;
  182.     short            endi;
  183.     unsigned char    *temp="\pYOU ARE A";
  184.     unsigned char    *temp2="\pWINNER!";
  185.     PicHandle        thePic;
  186.     
  187.     if (theDepth>2)
  188.     {
  189.         GetForeColor(&oldForeColor);
  190.         GetBackColor(&oldBackColor);
  191.     }
  192.     
  193.     GetPort(&curPort);
  194.     if (!EndGameShowingQQ())
  195.         gBackgroundPict=DrawThePicture(gBackgroundPict, 200, 0, 0);
  196.     else
  197.     {
  198.         thePic=GetPicture((theDepth>2) ? 134 : 135);
  199.         FillRect(&(curPort->portRect), &qd.black);
  200.         TextFont(144);
  201.         TextSize(24);
  202.         TextMode(srcXor);
  203.         MoveTo(150-StringWidth(temp)/2, 140);
  204.         DrawString(temp);
  205.         SetRect(&theRect, 0, 150, 300, 220);
  206.         DrawPicture(thePic, &theRect);
  207.         MoveTo(150-StringWidth(temp2)/2, 250);
  208.         DrawString(temp2);
  209.         ReleaseResource((Handle)thePic);
  210.     }    
  211.     DrawCurrentWord(theWindow);
  212.     
  213.     if (!EndGameShowingQQ())
  214.     {
  215.         if (GameInProgressQQ())
  216.             HighlightChar(theWindow);
  217.         
  218.         endi=(GameInProgressQQ()) ? gNumTries : (gNumTries==MAX_TRIES) ? gNumTries : gNumTries+1;
  219.         for (i=0; i<endi; i++)
  220.         {
  221.             MoveTo(20+(GetWindowWidth(theWindow))/2-4*CharWidth(' '),105+i*12);
  222.             Mymemcpy((Ptr)((long)tempStr+1), gHumanWord[i], gNumLetters);
  223.             tempStr[0]=gNumLetters;
  224.             DrawString(tempStr);
  225.             DrawString("\p    ");
  226.             NumToString(gNumRight[i], tempStr);
  227.             DrawChar(tempStr[1]);
  228.         }
  229.     
  230.         theRect.top=90;
  231.         theRect.bottom=122;
  232.         theRect.left=43;
  233.         theRect.right=theRect.left+32;
  234.         for (i=0; i<3; i++)
  235.         {
  236.             if (theDepth>2)
  237.                 PlotCIcon(&theRect, gColorIcons[i]);
  238.             else
  239.                 PlotIcon(&theRect, gBWIcons[i]);
  240.             theRect.top+=35;
  241.             theRect.bottom+=35;
  242.         }
  243.         if (theDepth>2)
  244.             PlotCIcon(&theRect, gColorIcons[2]);
  245.         else
  246.             PlotIcon(&theRect, gBWIcons[2]);
  247.         theRect.top+=35;
  248.         theRect.bottom+=35;
  249.         if (theDepth>2)
  250.             PlotCIcon(&theRect, gColorIcons[1]);
  251.         else
  252.             PlotIcon(&theRect, gBWIcons[1]);
  253.         
  254.         oldChar=gWhichChar;
  255.         gWhichChar=0x0a;
  256.         DrawOneChar(theWindow);
  257.         gWhichChar=oldChar;
  258.     }
  259.     
  260.     if (theDepth>2)
  261.     {
  262.         RGBForeColor(&oldForeColor);
  263.         RGBBackColor(&oldBackColor);
  264.     }
  265. }
  266.  
  267. Boolean CopybitsTheMainWindow(WindowPtr theWindow, WindowPtr offscreenWindowPtr)
  268. /* returns TRUE if copybits has been dealt with, FALSE if it still needs to be done */
  269. {
  270.     if ((gAnimation) && (gWhichWipe!=0))
  271.     {
  272.         SetPort(theWindow);
  273.         FillRect(&(theWindow->portRect), &qd.black);
  274.         DoTheWipe(offscreenWindowPtr, theWindow);
  275.         
  276.         return TRUE;
  277.     }
  278.     else gWhichWipe=0;
  279.     
  280.     return FALSE;
  281. }
  282.